<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>忘记密码</title>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css">
    
    <script src="__PUBLIC__/layui/layui.js"></script>
    <script src="__PUBLIC__/admin/js/jquery.min.js"></script>
 
</head>
<style type="text/css">
    input::-webkit-input-placeholder {
        color: rgb(201,211,215);
    }
    input:-ms-input-placeholder{
        color: rgb(201,211,215);
    }
    input::-moz-placeholder, textarea::-moz-placeholder {
        color: rgb(201,211,215);
    }input::-webkit-input-placeholder {
             color: rgb(201,211,215);
     }
    input:-ms-input-placeholder{
        color: rgb(201,211,215);
    }
    input::-moz-placeholder, textarea::-moz-placeholder {
        color: rgb(201,211,215);
    }



    .login-main {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 350px;
        margin: 0 auto;
    }
     
    .login-main header {
        margin-top: 150px;
        height: 35px;
        line-height: 35px;
        font-size: 30px;
        font-weight: 100;
        text-align: center;
    }
     
    .login-main header, .login-main form, .login-main form .layui-input-inline {
        margin-bottom: 15px;
    }
     
    .login-main form .layui-input-inline, .login-main form .layui-input-inline input, .login-main form .layui-input-inline button {
        width: 100%;
    }
     
    .login-main form .login-btn {
        margin-bottom: 5px;
    }

    .jianbian{
        background:-webkit-linear-gradient(top,#fff,#5e96e4 40%,#5e96e4 60%,#fff);
        -webkit-background-clip:text;
        -webkit-text-fill-color:transparent;
        text-transform:uppercase;
    }
</style>
<body class="custom-background-image" >
 
    <div class="login-main" >
        <img src="../../../../Public/img/title.png" style="position: relative;left: -16px;height: 180px;width: 380px;margin-top: 80px;">
        <!-- <header class="layui-elip" style="margin-top: 10px;color: #fff">找 回 密 码</header> -->
        <form class="layui-form">
            <div class="layui-input-inline">
                <input type="text" id="phone"  name="phone" required lay-verify="required|phone" placeholder="手机号" autocomplete="off" class="layui-input" style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);">
            </div>
            <div class="layui-input-inline">
                <input type="text" name="code" required lay-verify="required" placeholder="验证码" autocomplete="off" class="layui-input" style="width: 50%;float: left;background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);">
                
                <a  class="layui-btn" id="btn-send" onclick="sendmsg()" style="width: 50%;float: right;height: 38px;background: rgb(240,222,112);color: #000;font-size: 18px;">发送短信</a>
            </div>
            <div class="layui-input-inline">
                <input type="password" name="password" required lay-verify="required" placeholder="新密码" autocomplete="off" class="layui-input" style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);">
            </div>
            <div class="layui-input-inline">
                <input type="password" name="confirmpassword" required lay-verify="required" placeholder="确认新密码" autocomplete="off" class="layui-input" style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);">
            </div>
            
            <div class="layui-input-inline login-btn">
                <button lay-submit lay-filter="forget" class="layui-btn" style="background: rgb(240,222,112);color: #000;font-size: 18px;">重置密码</button>
            </div>
            <div class="layui-input-inline">
                <a href="{:U('Common/login')}" style="text-decoration: underline;float: right;height: 38px;color: rgb(240,222,112);">返回登录</a>
            </div>
        </form>
    </div>
     
     
    <script type="text/javascript">
        window.onload = function(){
            if(top.location!=self.location)
            {
                top.location=self.location;
            }
        }
        var countdown=60; 
        
        // 发送验证码
        function sendmsg(){
        	var phone = $("#phone").val().trim();
        	if (isPhoneNo(phone) == false) {
                layer.msg('手机号格式不正确');
                return false;
            }else{
            	$.ajax({
                    type:'post',
                    url:"{:U('Common/ctrl_sendmsg')}",
                    data:{phone:phone,type:2},
                    dataType:'json',
                    success:function (rtJson) {
                        if (rtJson.code == 1){
                        	layer.msg(rtJson.msg);
                            // location.href = "{:U('Common/login')}";
                            var obj = $("#btn-send");
    						settime(obj);

                        }
                    }
                });
            }
            return false;
        }

        function settime(obj) { //发送验证码倒计时
		    if (countdown == 0) { 
		        // obj.attr('disabled',false); 
		        $("#btn-send").removeClass('layui-btn-disabled').removeAttr('disabled',"true"); 
		        obj.text("发送短信");
		        countdown = 60; 
		        return;
		    } else { 
		        // obj.attr('disabled',true);
		        $('#btn-send').addClass("layui-btn-disabled").attr('disabled',"true");
		        obj.text("重新发送(" + countdown + ")");
		        countdown--; 
		    } 
			setTimeout(function() { 
		    	settime(obj);
			},1000) 
		}

        // 验证手机格式
		function isPhoneNo(phone) {
		    var pattern = /^1\d{10}$/;
		    return pattern.test(phone);
		}

        // 重置密码
        layui.use(['form','layer','jquery'], function () {
     
            // 操作对象
            var form = layui.form;
            var $ = layui.jquery;
            form.on('submit(forget)',function (data) {
                newpwd = data.field.password.trim();
                confirm_newpwd = data.field.confirmpassword.trim();
                if (newpwd != confirm_newpwd) {
                	layer.msg('两次密码不一致');
                	return false;
                }

				if (newpwd.length < 6 || confirm_newpwd.length < 6) {
					layer.msg('新密码长度过短，建议长于>=6');
					return false;
				}

                layer.confirm('确定要重置密码？',{offset:'none'},function(index){

	                $.ajax({
	                    type:'post',
	                    url:"{:U('Common/ctrl_forget')}",
	                    data:data.field,
	                    dataType:'json',
	                    success:function (rtJson) {
	                        if (rtJson.code == 1){
	                        	layer.msg(rtJson.msg);
	                            location.href = "{:U('Common/login')}";

	                        }else{
	                            layer.msg(rtJson.msg);
	                        }
	                    }
	                });
                });
                return false;
            })
     
        });

        
    </script>
</body>
</html>